#############################################################################
# This makefile is used as the driver to build the chosen RTL.  For         #
# appropriate command line switches and environment variables, see          #
# rules.mak                                                                 #
#############################################################################
!include rules.mak

#############################################################################
# Build the command line.  NOTE: The code here is based on rules.mak.  If   #
# rules.mak is enhanced or modified, make the results must be reflected     #
# here as well!!!                                                           #
#############################################################################
#
# The -l switch is an undocumented switch for MAKE.EXE (now on by default)
# which allows the commandline of a command to exceed 128 chars.  The
# default behavior is to report an error for any line exceeding 128.
#
CMDLINE = TARGET_OS=$(TARGET_OS) 

!if !$d(MINIRTL)
# Turn off MBCS for now to bootstrap
CMDLINE = $(CMDLINE) -DMBCS
!endif

!if $d(MINIRTL)
CMDLINE = $(CMDLINE) -DMINIRTL
!endif

!if $d(MINIRTL_EDG)
CMDLINE = $(CMDLINE) -DMINIRTL_EDG -DELF -DEDG
!endif

!if $d(INTERNAL_BUILD)
CMDLINE = $(CMDLINE) -DINTERNAL_BUILD
!endif

!if $d(DEBUG)
    CMDLINE = $(CMDLINE) -DDEBUG
!endif

!if $d(DLL)
    CMDLINE = $(CMDLINE) -DDLL
!endif

#!if $d(MODEL)
#    CMDLINE = $(CMDLINE) MODEL=$(MODEL)
#!endif

!if $d(MT)
    CMDLINE = $(CMDLINE) -DMT
!endif

!if $d(MAGIC)
    CMDLINE = $(CMDLINE) -DMAGIC
!endif

!if $d(PCH)
    CMDLINE = $(CMDLINE) -DPCH
!endif

!if $d(MAKEFLAGS)
    CMDLINE = $(CMDLINE) -$(MAKEFLAGS)
!endif

#############################################################################
# What needs to be built.                                                   #
#############################################################################
!if $d(INTERNAL_BUILD)
all : start srcdirs builddir end
!else
all : createdir start srcdirs builddir end

createdir:
  @if not exist $(PSDKDIR) mkdir $(PSDKDIR)
  @if not exist $(RTLROOT)\obj mkdir $(RTLROOT)\obj
  @if not exist $(RTLROOT)\obj\win32 mkdir $(RTLROOT)\obj\win32
  @if not exist $(RTLROOT)\obj\win32\obj mkdir $(RTLROOT)\obj\win32\obj
  @if not exist $(RTLROOT)\obj\win32\objx mkdir $(RTLROOT)\obj\win32\objx
  @if not exist $(RTLROOT)\obj\win32\objmt mkdir $(RTLROOT)\obj\win32\objmt
  @if not exist $(RTLROOT)\obj\win32\objmtx mkdir $(RTLROOT)\obj\win32\objmtx
  @if not exist $(RTLROOT)\obj\win32\objmgmt mkdir $(RTLROOT)\obj\win32\objmgmt
  @if not exist $(RTLROOT)\obj\win32\objmgmtx mkdir $(RTLROOT)\obj\win32\objmgmtx
!endif

srcdirs : $(SRCDIRS)

BUILDDIR = $(LIBDIR)

builddir : $(BUILDDIR)

#############################################################################
# For each source directory build whatever is necessary.                    #
#############################################################################
$(SRCDIRS) :
    @echo .
    @echo [*************** $* ***************]
    @echo .
    &cd $*
    @echo Processing [$(CMDLINE)] $* >> $(RTLROOT)\progress.txt
    $(MAKE) -I$(RTLROOT) $(CMDLINE) objs

$(BUILDDIR) :
    @echo .
    @echo Processing [$(CMDLINE)] $* >> $(RTLROOT)\progress.txt
    @echo [*************** $* ***************]
    @echo .
    cd $*
!if $d(DLL)
         $(MAKE) -I$(RTLROOT) $(CMDLINE) dll
!else
     $(MAKE) -I$(RTLROOT) $(CMDLINE) objs
     $(MAKE) -I$(RTLROOT) $(CMDLINE) lib
!endif

#############################################################################
# Do whatever is necessary at the start and end of the build.               #
#############################################################################
start :
!if !$d(RTLSOURCE)
    @echo Date / Time : %_date %_time
    @echo Current path: %PATH%
!endif
    # timenow.h is never used
    #@$(RTLROOT)\tools\timenow.exe DATETIME_STRING > $(RTLROOT)\include\rtlinc\timenow.h
    @echo .
    @echo [***************** Borland C++ Run Time Libary *****************]
    @echo .
    @echo Starting RTL Build [$(CMDLINE)] > $(RTLROOT)\progress.txt
!if $d(DLL)
    if exist $(LIBDIR)\dll.rsp del $(LIBDIR)\dll.rsp
    echo $(LIBDIR)\\$(DLLC0)+ > $(LIBDIR)\dll.rsp
    if exist $(LIBDIR)\import.rsp del $(LIBDIR)\import.rsp
    if exist $(LIBDIR)\import_w.rsp del $(LIBDIR)\import_w.rsp
!else
    if exist $(LIBDIR)\tlib.rsp del $(LIBDIR)\tlib.rsp
    if exist $(LIBDIR)\ar.rsp del $(LIBDIR)\ar.rsp
!endif

end :
    @echo Ending RTL Build [$(CMDLINE)] >> $(RTLROOT)\progress.txt
    cd $(RTLROOT)
!if !$d(KEEP_RTL_TEMP_FILES)
!if $d(DLL)
    if exist $(LIBDIR)\dll.rsp del $(LIBDIR)\dll.rsp
    if exist $(LIBDIR)\import.rsp del $(LIBDIR)\import.rsp
    if exist $(LIBDIR)\import_w.rsp del $(LIBDIR)\import_w.rsp
!else
    if exist $(LIBDIR)\tlib.rsp del $(LIBDIR)\tlib.rsp
    if exist $(LIBDIR)\ar.rsp del $(LIBDIR)\ar.rsp
!endif
!endif
!if !$d(RTLSOURCE)
    @echo %_date %_time
!endif

!if $d(INTERNAL_BUILD)
clean :
    call clean.btm all
!endif

